﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "PUB_DEVICE";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<table style="width:100%">
<tbody>
    <tr>
        <td style="width:330px;vertical-align: top">
             <div class="mvctool">
             </div>
            <table id="ListParent"></table>
        </td>        <td style="width:3px;"></td>
        <td style="vertical-align:top">
             <div class="mvctool">
                 <input id="txtQuery" type="text" class="searchText" placeholder="可根据设备名称、型号、IP地址、端口查询"/>
                 @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query,ref perm, "Query", true)
                 @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create,ref perm, "Create", true)
                 @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit,ref perm, "Edit", true)
                 @Html.ToolButton("btnDetails", "fa fa-book", Resource.Details,ref perm, "Details", true)
                 @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete,ref perm, "Delete", true)
             </div>
            <table id="List"></table>
        </td>
    </tr>
</tbody>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#ListParent').datagrid({
            url: '@Url.Action("GetListParent")',
            width: 270,
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'NODE_ID',
            sortOrder: 'desc',
            idField: 'NODE_ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                var allRows = $('#ListParent').datagrid('getRows');
                if (allRows.length > 0) {
                    var currow = allRows[0];
                    setTimeout(function () {
                        $('#ListParent').datagrid('selectRow', 0);
                        $('#List').datagrid("load", { ParentId: currow.NODE_ID });
                    }, 800);
                }
            },
            columns: [[
                 { field: 'NODE_CODE', title: '匹配码(枚举Node)', width: 80, sortable: true, hidden: true },
                { field: 'ENABLED', title: '当前节点是否启用 1:启用 0:停用', width: 80, sortable: true, hidden: true },
                { field: 'NODE_ID', title: '节点编号', width: 80, sortable: true, hidden: true },
                { field: 'NODE_NAME', title: '节点名称', width: 80, sortable: true },
                { field: 'POSTION', title: '是否双向进出设备', width: 80, sortable: true, formatter: function (value) { return EnableFormatterNember(value) } },
                { field: 'TACHE_ID', title: '环节编号', width: 80, sortable: true, hidden: true }
            ]]
         ,onClickRow: function(index, row) {
             $('#List').datagrid("load", { ParentId: row.NODE_ID });
}
        }).datagrid('getPager');
         $(window).resize(function() {
             resizeLayout();
         });
        $('#List').datagrid({
            url: '@Url.Action("GetList")?parentId=1',
            width: SetGridWidthSub(290),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'DEVICE_ID',
            sortOrder: 'desc',
            idField: 'DEVICE_ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function(data) {                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'DEVICE_ID', title: '设备编号', width: 80, hidden: true },
                { field: 'DEVICE_NAME', title: '设备名称', width: 80, sortable: true },
                { field: 'OF_NODEName', title: '节点名称', width: 80, sortable: true },
                { field: 'MODELNAME', title: '设备型号', width: 80, sortable: true },
                { field: 'IP', title: 'IP地址', width: 80,sortable:true },
                { field: 'PORT', title: '端口', width: 80,sortable:true },
                { field: 'PARAMETERS', title: '控制参数', width: 80,sortable:true,hidden:true },
                { field: 'NET_STATUS', title: '网络状态', width: 80, sortable: true, formatter: function (value) { return CustomFormatter(value,"正常","异常") } },
                { field: 'NET_STATUS_TIME', title: '最新诊断时间', width: 80,sortable:true },
                { field: 'NODE_ID', title: '类别名称', width: 80,hidden:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
        {
            $("#List").datagrid('load');
        }
        else
        {
            $("#List,#ListParent").datagrid('reload');
        }
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("Create")?NodeId="+row.NODE_ID+"'></iframe>");
                $("#modalwindow").window({ title: Lang.Create, width: 700, height: 400, iconCls: 'fa fa-plus' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '请先选择节点名称！'); }
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Edit")?id=" + row.DEVICE_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 700, height: 400, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='98%' scrolling='auto' frameborder='0' src='@Url.Action("Details")?id=" + row.DEVICE_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Details', width: 700, height: 400, iconCls: 'fa fa-list' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnQuery").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", { queryStr: queryStr, parentId: row.NODE_ID });
            } else { $.messageBox5s(Lang.Tip, '请先选择节点名称！'); }

        });
        $("#btnDelete").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm(index_lang_tip, '@Resource.YouWantToDeleteTheSelectedRecords', function (r) {
	                    if (r) {
	                        $.post("@Url.Action("Delete")?id=" + row.DEVICE_ID, function (data) {
	                            if (data.type == 1)
	                                $("#List").datagrid('load');
	                            $.messageBox5s(Lang.Tip, data.message);
	                        }, "json");
	                    }
	                });
	            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	        });
        $("#btnImport").click(function() {
             $("#txtExcelPath").val("");
             $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 155, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnExport").click(function() {
          $.post("@Url.Action("CheckExportData")", function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")";
                }
                else
                {
                $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });
    });
    function ImportData()
    {
        showLoading();
        var url = "@Url.Action("Import")?filePath="+$("#txtExcelPath").val();
        $.post(url, function(data) {
            if (data.type == 1)
            {
             $("#List").datagrid('load');
             $('#uploadExcel').window('close');
             $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
        }, "json");
    }
    function resizeLayout()
     {
         setTimeout(function () {
             $('#ListParent').datagrid('resize', {
             }).datagrid('resize', {
                 height: SetGridHeightSub(81)
             });
             $('#List').datagrid('resize', {
             }).datagrid('resize', {
                 width: $(window).width() - 450,
                 height: SetGridHeightSub(45)
             });
         },100);
	    }
</script>

